home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <GL/glu.h>
- #include <GL/glx.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <X11/keysym.h>
- #include <string.h>
- #include <math.h>
-
- static int RGBA_SB_attributes[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 1,
- None,
- };
-
- static int RGBA_DB_attributes[] = {
- GLX_RGBA,
- GLX_RED_SIZE, 1,
- GLX_GREEN_SIZE, 1,
- GLX_BLUE_SIZE, 1,
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 1,
- None,
- };
-
- static int CI_SB_attributes[] = {
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 1,
- None,
- };
-
- static int CI_DB_attributes[] = {
- GLX_DOUBLEBUFFER,
- GLX_DEPTH_SIZE, 1,
- GLX_STENCIL_SIZE, 1,
- None,
- };
-
- #define PI 3.14159265358979323846
-
- static int W = 300;
- static int H = 300;
-
- static int rgb;
- static int doubleBuffer;
- static int indexBits;
-
- static long clearMask = GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT;
- static int overStrike = 0;
- static int smooth=0;
- static int lighting=1;
- static int depth=1;
- static int fog=0;
- static int stepmode=0;
- static int checkersize = 2;
- static int spinmode = 0;
- static int curframe;
- static int nextframe = 0;
- static float height = 0.2;
- static int contouring;
-
- static int colorIndexes1[3];
- static int colorIndexes2[3];
-
- Display *dpy;
- Window window;
- Colormap cmap;
-
- #define YWIDTH 10
- #define XWIDTH 10
- #define FRAMES 10
-
- struct facet {
- float color[3];
- float normal[3];
- };
-
- struct coord {
- float vertex[3];
- float normal[3];
- };
-
- struct mesh {
- int xwidth, ywidth;
- int nfacets;
- int ncoords;
- int frames;
- struct coord *coords;
- struct facet *facets;
- } theMesh;
-
- #define GETCOORD(frame, x, y) (&(theMesh.coords[frame * theMesh.ncoords + (x) + (y) * (theMesh.xwidth+1)]))
-
- #define GETFACET(frame, x, y) (&(theMesh.facets[frame * theMesh.nfacets + (x) + (y) * theMesh.xwidth]))
-
- unsigned char contourTexture[] = {
- 255, 255, 255, 255,
- 255, 255, 255, 255,
- 255, 255, 255, 255,
- 127, 127, 127, 127,
- };
-
- unsigned char contourTexture2[] = {
- 255, 255, 255, 255,
- 255, 127, 127, 127,
- 255, 127, 127, 127,
- 255, 127, 127, 127,
- };
-
- static void setColorMap(void)
- {
- int i;
- int j;
- int *indexes;
- float *color;
- static float green[3] = { 0.2, 1.0, 0.2 };
- static float red[3] = { 1.0, 0.2, 0.2 };
- float r,g,b;
- float percent;
- long buf[4];
- int entries;
- XColor *colors;
-
- entries = (1 << indexBits) - 1;
- colorIndexes1[0] = 1;
- colorIndexes1[1] = 1 + (entries * 0.3);
- colorIndexes1[2] = (entries * 0.5);
- colorIndexes2[0] = 1 + (entries * 0.5);
- colorIndexes2[1] = 1 + (entries * 0.8);
- colorIndexes2[2] = entries;
-
- colors = (XColor*) calloc(entries+1, sizeof(XColor));
-
- for (i=0; i<2; i++) {
- switch (i) {
- case 0:
- color=green;
- indexes=colorIndexes1;
- break;
- case 1:
- color=red;
- indexes=colorIndexes2;
- break;
- }
- for (j=indexes[0]; j<indexes[1]; j++) {
- /* 20% ambient, 80% diffuse */
- percent=0.2 + 0.8*(j-indexes[0]) / (float) (indexes[1]-indexes[0]);
- colors[j].pixel = j;
- colors[j].red = 65535 * (percent*color[0]) + 0.5;
- colors[j].green = 65535 * (percent*color[1]) + 0.5;
- colors[j].blue = 65535 * (percent*color[2]) + 0.5;
- colors[j].flags = DoRed|DoGreen|DoBlue;
- }
- for (j=indexes[1]; j<=indexes[2]; j++) {
- /* Specular goes to white */
- percent=(j-indexes[1]) / (float) (indexes[2]-indexes[1]);
- colors[j].pixel = j;
- colors[j].red = 65535 * (percent*(1-color[0]) + color[0]) + 0.5;
- colors[j].green = 65535 * (percent*(1-color[1]) + color[1]) + 0.5;
- colors[j].blue = 65535 * (percent*(1-color[2]) + color[2]) + 0.5;
- colors[j].flags = DoRed|DoGreen|DoBlue;
- }
- }
- XStoreColors(dpy, cmap, colors, entries+1);
- }
-
- static void initialize(int xwidth, int ywidth, int frames)
- {
- int nfacets;
- int ncoords;
- int i,j;
- int frameno;
- float x, y;
- float angle;
- float d;
- struct coord *coord;
- struct facet *facet;
- float *pt1, *pt2, *pt3;
- float dp1[3], dp2[3];
-
- theMesh.xwidth=xwidth;
- theMesh.ywidth=ywidth;
- theMesh.frames=frames;
-
- nfacets=xwidth*ywidth;
- ncoords=(xwidth+1)*(ywidth+1);
-
- theMesh.ncoords=ncoords;
- theMesh.nfacets=nfacets;
-
- theMesh.coords=
- (struct coord *) malloc(frames * ncoords * sizeof(struct coord));
- theMesh.facets=
- (struct facet *) malloc(frames * nfacets * sizeof(struct facet));
- if (theMesh.coords == NULL || theMesh.facets == NULL) {
- printf("Out of memory.\n");
- exit(-1);
- }
-
- for (frameno = 0; frameno < frames; frameno++) {
- for (i = 0; i <= xwidth; i++) {
- x = i / (float) xwidth;
- for (j = 0; j <= ywidth; j++) {
- y = j / (float) ywidth;
-
- d=sqrt(x*x + y*y);
- if (d == 0.0) d=0.0001;
- angle=2*PI*d + (2*PI/frames * frameno);
-
- coord = GETCOORD(frameno, i, j);
-
- coord->vertex[0] = x - 0.5;
- coord->vertex[1] = y - 0.5;
- coord->vertex[2] = (height - height*d) * cos(angle);
- coord->normal[0] =
- -(height/d) * x * ((1-d) * 2*PI*sin(angle) + cos(angle));
- coord->normal[1] =
- -(height/d) * y * ((1-d) * 2*PI*sin(angle) + cos(angle));
- coord->normal[2] = -1;
-
- d = 1.0 / sqrt(coord->normal[0] * coord->normal[0] +
- coord->normal[1] * coord->normal[1] + 1);
- coord->normal[0] *= d;
- coord->normal[1] *= d;
- coord->normal[2] *= d;
- }
- }
- for (i = 0; i < xwidth; i++) {
- for (j = 0; j < ywidth; j++) {
- facet = GETFACET(frameno, i, j);
- if (((i / checkersize) % 2) ^ (j / checkersize) % 2) {
- if (rgb) {
- facet->color[0] = 1.0;
- facet->color[1] = 0.2;
- facet->color[2] = 0.2;
- } else {
- facet->color[0] = colorIndexes1[0];
- facet->color[1] = colorIndexes1[1];
- facet->color[2] = colorIndexes1[2];
- }
- } else {
- if (rgb) {
- facet->color[0] = 0.2;
- facet->color[1] = 1.0;
- facet->color[2] = 0.2;
- } else {
- facet->color[0] = colorIndexes2[0];
- facet->color[1] = colorIndexes2[1];
- facet->color[2] = colorIndexes2[2];
- }
- }
- pt1 = GETCOORD(frameno, i, j)->vertex;
- pt2 = GETCOORD(frameno, i, j+1)->vertex;
- pt3 = GETCOORD(frameno, i+1, j+1)->vertex;
-
- dp1[0] = pt2[0]-pt1[0];
- dp1[1] = pt2[1]-pt1[1];
- dp1[2] = pt2[2]-pt1[2];
-
- dp2[0] = pt3[0]-pt2[0];
- dp2[1] = pt3[1]-pt2[1];
- dp2[2] = pt3[2]-pt2[2];
-
- facet->normal[0] = dp1[1] * dp2[2] - dp1[2] * dp2[1];
- facet->normal[1] = dp1[2] * dp2[0] - dp1[0] * dp2[2];
- facet->normal[2] = dp1[0] * dp2[1] - dp1[1] * dp2[0];
-
- d = 1.0 / sqrt(facet->normal[0] * facet->normal[0] +
- facet->normal[1] * facet->normal[1] +
- facet->normal[2] * facet->normal[2]);
-
- facet->normal[0] *= d;
- facet->normal[1] *= d;
- facet->normal[2] *= d;
- }
- }
- }
- }
-
- static void initMaterials(void)
- {
- static float ambient[] = { 0.1, 0.1, 0.1, 1.0 };
- static float diffuse[] = { 0.5, 1.0, 1.0, 1.0 };
- static float position[] = { 90.0, 90.0, 150.0, 0.0 };
- static float front_mat_shininess[] = { 60.0 };
- static float front_mat_specular[] = { 0.2, 0.2, 0.2, 1.0 };
- static float front_mat_diffuse[] = { 0.5, 0.28, 0.38, 1.0 };
- static float back_mat_shininess[] = { 60.0 };
- static float back_mat_specular[] = { 0.5, 0.5, 0.2, 1.0 };
- static float back_mat_diffuse[] = { 1.0, 1.0, 0.2, 1.0 };
- static float lmodel_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
- static float lmodel_twoside[] = { GL_TRUE };
- static float fog_color[] = {0.0, 0.0, 0.0, 1.0};
-
- glFrontFace(GL_CW);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
-
- glMatrixMode(GL_PROJECTION);
- gluPerspective(450, 1.0, 0.5, 10.0);
- glClearColor(0.0, 0.0, 0.0, 0.0);
-
- glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
- glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
- glLightfv(GL_LIGHT0, GL_POSITION, position);
-
- glMaterialfv(GL_FRONT, GL_SHININESS, front_mat_shininess);
- glMaterialfv(GL_FRONT, GL_SPECULAR, front_mat_specular);
- glMaterialfv(GL_FRONT, GL_DIFFUSE, front_mat_diffuse);
- glMaterialfv(GL_BACK, GL_SHININESS, back_mat_shininess);
- glMaterialfv(GL_BACK, GL_SPECULAR, back_mat_specular);
- glMaterialfv(GL_BACK, GL_DIFFUSE, back_mat_diffuse);
-
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
- glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
-
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glShadeModel(GL_FLAT);
-
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- if (rgb) {
- glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
- glEnable(GL_COLOR_MATERIAL);
- glFogf(GL_FOG_END, 5.0);
- glFogf(GL_FOG_START, 0.25);
- glFogi(GL_FOG_MODE, GL_LINEAR);
- glFogfv(GL_FOG_COLOR, fog_color);
- } else {
- setColorMap();
- }
- }
-
- static void redraw(void)
- {
- struct coord *coord;
- struct facet *facet;
- float *lastcolor;
- float *thiscolor;
- int i,j;
-
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(clearMask);
-
- if (!stepmode) curframe++;
-
- if (!stepmode && spinmode) {
- glRotatef(5.0, 0.0, 0.0, 1.0);
- }
-
- while (nextframe) {
- curframe++;
- if (spinmode) {
- glRotatef(5.0, 0.0, 0.0, 1.0);
- }
- nextframe--;
- }
- nextframe = 0;
- while (curframe >= theMesh.frames) curframe -= theMesh.frames;
-
- for (i = 0; i < theMesh.xwidth; i++) {
- glBegin(GL_QUAD_STRIP);
- lastcolor = NULL;
- for (j = 0; j < theMesh.ywidth; j++) {
- facet=GETFACET(curframe, i, j);
- if (!smooth && lighting) {
- glNormal3fv(facet->normal);
- }
- if (lighting) {
- if (rgb) {
- thiscolor = facet->color;
- glColor3fv(facet->color);
- } else {
- thiscolor = facet->color;
- glMaterialfv(GL_FRONT_AND_BACK, GL_COLOR_INDEXES,
- facet->color);
- }
- } else {
- if (rgb) {
- thiscolor = facet->color;
- glColor3fv(facet->color);
- } else {
- thiscolor = facet->color;
- glIndexf(facet->color[1]);
- }
- }
-
- /* Need to draw first two verts? */
- if (!lastcolor ||
- (thiscolor[0] != lastcolor[0] && smooth)) {
- if (lastcolor) {
- glEnd();
- glBegin(GL_QUAD_STRIP);
- }
- coord=GETCOORD(curframe, i, j);
- if (smooth && lighting) {
- glNormal3fv(coord->normal);
- }
- glVertex3fv(coord->vertex);
-
- coord=GETCOORD(curframe, i+1, j);
- if (smooth && lighting) {
- glNormal3fv(coord->normal);
- }
- glVertex3fv(coord->vertex);
- }
-
- coord=GETCOORD(curframe, i, j+1);
- if (smooth && lighting) {
- glNormal3fv(coord->normal);
- }
- glVertex3fv(coord->vertex);
-
- coord=GETCOORD(curframe, i+1, j+1);
- if (smooth && lighting) {
- glNormal3fv(coord->normal);
- }
- glVertex3fv(coord->vertex);
-
- lastcolor = thiscolor;
- }
- glEnd();
- }
- glFlush();
- if (doubleBuffer) {
- glXSwapBuffers(dpy, window);
- }
- }
-
- static void animate(void)
- {
- int rv, needRedraw;
- KeySym ks;
- char buf[10];
- XEvent ev;
-
- needRedraw = 1;
- for (;;) {
- while (XPending(dpy)) {
- XNextEvent(dpy, &ev);
-
- switch (ev.type) {
- case Expose:
- needRedraw = 1;
- break;
- case ConfigureNotify:
- W = ev.xconfigure.width;
- H = ev.xconfigure.height;
- glViewport(0, 0, W, H);
- needRedraw = 1;
- break;
- case KeyPress:
- rv = XLookupString(&ev.xkey, buf, sizeof(buf), &ks, 0);
- needRedraw = 1;
- switch (ks) {
- case XK_Escape:
- return;
- case XK_C:
- case XK_c:
- contouring++;
- if (contouring == 1) {
- static GLfloat map[4] = { 0, 0, 20, 0 };
-
- glTexImage2D(GL_TEXTURE_2D, 0, 3, 4, 4, 0,
- GL_LUMINANCE, GL_UNSIGNED_BYTE,
- (const unsigned char *) contourTexture);
- glEnable(GL_TEXTURE_2D);
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
- glTexGenfv(GL_S, GL_OBJECT_PLANE, map);
- glTexGenfv(GL_T, GL_OBJECT_PLANE, map);
- } else if (contouring == 2) {
- static GLfloat map[4] = { 0, 0, 20, 0 };
-
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
- glPushMatrix();
- glLoadIdentity();
- glTexGenfv(GL_S, GL_EYE_PLANE, map);
- glTexGenfv(GL_T, GL_EYE_PLANE, map);
- glPopMatrix();
- } else {
- contouring = 0;
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- }
- break;
- case XK_S: case XK_s:
- smooth=1-smooth;
- if (smooth) {
- glShadeModel(GL_SMOOTH);
- } else {
- glShadeModel(GL_FLAT);
- }
- break;
- case XK_L: case XK_l:
- lighting=1-lighting;
- if (lighting) {
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- if (rgb) {
- glEnable(GL_COLOR_MATERIAL);
- }
- } else {
- glDisable(GL_LIGHTING);
- glDisable(GL_LIGHT0);
- if (rgb) {
- glDisable(GL_COLOR_MATERIAL);
- }
- }
- break;
- case XK_D: case XK_d:
- depth=1-depth;
- if (depth) {
- glEnable(GL_DEPTH_TEST);
- clearMask |= GL_DEPTH_BUFFER_BIT;
- printf("Depth on\n");
- } else {
- glDisable(GL_DEPTH_TEST);
- clearMask &= ~GL_DEPTH_BUFFER_BIT;
- printf("Depth off\n");
- }
- break;
- case XK_O: case XK_o:
- overStrike = 1 - overStrike;
- if (overStrike) {
- glEnable(GL_STENCIL_TEST);
- glStencilFunc(GL_EQUAL, 0, ~0);
- glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
- clearMask |= GL_STENCIL_BUFFER_BIT;
- printf("Overstrike on\n");
- } else {
- glDisable(GL_STENCIL_TEST);
- printf("Overstrike off\n");
- }
- break;
- case XK_F: case XK_f:
- if (rgb) {
- fog = !fog;
- fog ? glEnable(GL_FOG) : glDisable(GL_FOG);
- }
- break;
- case XK_space:
- stepmode=1-stepmode;
- break;
- case XK_N:
- case XK_n:
- if (stepmode) {
- nextframe++;
- }
- break;
- case XK_A:
- case XK_a:
- spinmode = 1-spinmode;
- break;
- default:
- break;
- }
- break;
- }
- }
- if (!stepmode || needRedraw) {
- redraw();
- needRedraw = 0;
- }
- if (stepmode) {
- XPeekEvent(dpy, &ev);
- }
- }
- }
-
- static void usage(void)
- {
- printf("\
- Usage: twave [-g width height] [-f frames] [-c] [-s] [-b checker size]\n\
- [-h height] [-geometry WxH+X+Y] [-a]\n\
- -g: Specify grid size (default is 10 by 10)\n\
- -f: Specify number of frames in a full cycle (default is 10)\n\
- -c: Run in color index mode\n\
- -s: Run in single buffered mode\n\
- -b: Specify size of checker on checker board (default is 2)\n\
- -h: Specify the height of the wave (default is 0.2)\n\
- -a: Don't start off animating.\n\
- -geometry: Specify window size and location\n\
- ");
- exit(-1);
- }
-
- static Bool WaitForMapNotify(Display *d, XEvent *e, char *arg)
- {
- if ((e->type == MapNotify) && (e->xmap.window == (Window)arg)) {
- return GL_TRUE;
- }
- return GL_FALSE;
- }
-
- int main(int argc, char **argv)
- {
- int xwidth, ywidth;
- int frames;
- int i;
- int *attrs;
- XVisualInfo *vi;
- XSetWindowAttributes swa;
- XEvent event;
- GLXContext cx;
- char window_title[100];
- XSizeHints sizehints;
- char *geometry = NULL;
-
- rgb=1;
- doubleBuffer = 1;
-
- xwidth=XWIDTH;
- ywidth=YWIDTH;
- frames=FRAMES;
- for (i=1; i<argc; i++) {
- if (!strcmp(argv[i], "-geometry")) {
- i++;
- geometry = argv[i];
- } else if (argv[i][0] == '-') {
- switch(argv[i][1]) {
- case 'g':
- i++;
- if (argv[i] == NULL) usage();
- xwidth=atoi(argv[i]);
- i++;
- if (argv[i] == NULL) usage();
- ywidth=atoi(argv[i]);
- if (xwidth <= 0 || ywidth <= 0) {
- printf("Non-positive widths not allowed.\n");
- return -1;
- }
- break;
- case 'f':
- i++;
- if (argv[i] == NULL) usage();
- frames=atoi(argv[i]);
- if (frames < 1) {
- printf("Must have at least 1 frame\n");
- return -1;
- }
- break;
- case 'h':
- i++;
- if (argv[i] == NULL) usage();
- height=atof(argv[i]);
- break;
- case 'c':
- rgb=0;
- break;
- case 's':
- doubleBuffer = 0;
- break;
- case 'a': /* animation off mode */
- stepmode = 1;
- break;
- case 'b':
- i++;
- if (argv[i] == NULL) usage();
- checkersize=atoi(argv[i]);
- if (checkersize < 1) {
- printf("Checker Size must be at least 1\n");
- return -1;
- }
- break;
- default:
- usage();
- }
- } else usage();
- }
-
- if (doubleBuffer) {
- if (rgb) {
- attrs = RGBA_DB_attributes;
- } else {
- attrs = CI_DB_attributes;
- }
- } else {
- if (rgb) {
- attrs = RGBA_SB_attributes;
- } else {
- attrs = CI_SB_attributes;
- }
- }
-
- dpy = XOpenDisplay(0);
- if (!dpy) {
- fprintf(stderr, "Can't connect to display \"%s\"\n", getenv("DISPLAY"));
- return -1;
- }
-
- vi = glXChooseVisual(dpy, DefaultScreen(dpy), attrs);
- if (!vi) {
- fprintf(stderr, "No matching visual on \"%s\"\n",
- getenv("DISPLAY"));
- return -1;
- }
-
- sizehints.flags = PPosition | PSize;
- sizehints.width = W;
- sizehints.height = H;
- sizehints.x = 10;
- sizehints.y = 10;
- if(geometry) {
- int flags, x, y, width, height;
-
- flags = XParseGeometry(geometry, &x, &y,
- (unsigned int *)&width,
- (unsigned int *)&height);
- if(WidthValue & flags) {
- sizehints.flags |= USSize;
- sizehints.width = width;
- W = width;
- }
- if(HeightValue & flags) {
- sizehints.flags |= USSize;
- sizehints.height = height;
- H = height;
- }
- if(XValue & flags) {
- if(XNegative & flags)
- x = DisplayWidth(dpy, DefaultScreen(dpy)) + x
- - sizehints.width;
- sizehints.flags |= USPosition;
- sizehints.x = x;
- }
- if(YValue & flags) {
- if(YNegative & flags)
- y = DisplayHeight(dpy, DefaultScreen(dpy)) + y
- - sizehints.height;
- sizehints.flags |= USPosition;
- sizehints.y = y;
- }
- }
- cmap = XCreateColormap(dpy, RootWindow(dpy, vi->screen), vi->visual,
- rgb ? AllocNone : AllocAll);
- swa.border_pixel = 0;
- swa.colormap = cmap;
- swa.event_mask = ExposureMask | StructureNotifyMask | KeyPressMask;
- window = XCreateWindow(dpy, RootWindow(dpy, vi->screen),
- sizehints.x, sizehints.y,
- sizehints.width, sizehints.height,
- 0, vi->depth, InputOutput, vi->visual,
- CWBorderPixel|CWColormap|CWEventMask, &swa);
- sprintf(window_title, "twave (%s %s)",
- rgb ? "RGB" : "CI",
- doubleBuffer ? "double buffered" : "single buffered");
- XSetStandardProperties(dpy, window, window_title, "twave", None,
- argv, argc, &sizehints);
- XSetWMColormapWindows(dpy, window, &window, 1);
- XMapWindow(dpy, window);
- XIfEvent(dpy, &event, WaitForMapNotify, (char*)window);
-
- cx = glXCreateContext(dpy, vi, 0, GL_TRUE);
- if (!glXMakeCurrent(dpy, window, cx)) {
- fprintf(stderr, "Can't make window current to context\n");
- return -1;
- }
- indexBits = vi->depth;
-
- glViewport(0, 0, W, H);
-
- initMaterials();
- initialize(xwidth, ywidth, frames);
-
- glEnable(GL_NORMALIZE);
- glMatrixMode(GL_MODELVIEW);
- glTranslatef(0.0, 0.4, -1.8);
- glScalef(2.0, 2.0, 2.0);
- glRotatef(-35.0, 1.0, 0.0, 0.0);
- glRotatef(35.0, 0.0, 0.0, 1.0);
-
- animate();
-
- return 0;
- }
-